package com.asdf.db.operations.airport;

import java.util.List;

import com.asdf.db.results.ResultStatus;
import com.asdf.db.results.airport.AirportResult;
import com.asdf.entities.Airport;

/**
 * @author Artem Barger
 * 
 * Operation which performs the airport inserting into 
 * relevant airports dataset. 
 *
 */
public class InsertAirport extends AirportOperation
{
	
	private Airport			airportToInsert		= null;
	
	/**
	 * Initialize "connection" with appropriate
	 * airports dataset.
	 * 
	 * @param dataSource airports data set.
	 */
	public InsertAirport( List< Airport> dataSource)
	{
		this.dataSource = dataSource;
	}
	
	/**
	 * Defines the airport to insert into database.
	 * 
	 * @param airport the actual airport.
	 */
	public void setAirport( Airport airport)
	{
		this.airportToInsert = airport;
	}
	
	@Override
	public AirportResult perform( )
	{
		AirportResult result = new AirportResult( );
		
		if ( this.dataSource.contains( airportToInsert))
		{
			result.setStatus( ResultStatus.AlreadyExist);
			return result;
		}
		
		dataSource.add( airportToInsert);
		
		result.setStatus( ResultStatus.OK);
		return result;
	}

}